<?php
/**
 * SocialEngine
 *
 * @category   Application_Extensions 
 * @package    Communityad
 * @copyright  Copyright 2009-2011 BigStep Technologies Pvt. Ltd.
 * @license    http://www.socialengineaddons.com/license/
 * @version    $Id: manage.tpl 2011-02-16 9:40:21Z SocialEngineAddOns $
 * @author     SocialEngineAddOns
 */
?>
<h2>
  <?php echo $this->translate('Community Ads Plugin') ?>
</h2>

<script type="text/javascript">

function multiDelete()
{
  return confirm("<?php echo $this->translate("Are you sure you want to delete the selected Communityad Blocks?") ?>");
}

function selectAll()
{
  var i;
  var multidelete_form = $('multidelete_form');
  var inputs = multidelete_form.elements;
  for (i = 1; i < inputs.length; i++) {
    if (!inputs[i].disabled) {
      inputs[i].checked = inputs[0].checked;
    }
  }
}
</script>

<?php if( count($this->navigation) ): ?>
<div class='communityad_admin_tabs'>
  <?php
    // Render the menu
    echo $this->navigation()->menu()->setContainer($this->navigation)->render()
  ?>
</div>
<?php endif; ?>
<h3 style="margin-bottom:6px;"><?php echo $this->translate("Manage Ad Blocks"); ?></h3>
<?php
	// Show Success message.
	if(isset($this->success_message))
	{
		echo '<ul class="form-notices" style="margin:0px;"><li style="float:left;">' . $this->translate('Successfully create') . ' ' . ucfirst($this->success_message) . ' ' . $this->translate('Communityad.') . '</li></ul>';
	}
?>
  <p>
  	<?php echo $this->translate("This page lists all the Ad Blocks created by you for displaying advertisements (Community Ads) on your site. When you create an Ad Block from here for a widgetized page of your site, you have the option to let this system automatically place the corresponding Ad Block Widget on that page. It is recommended that you create all your Ad Blocks from here, and not place them on the pages from the Layout Editor, to maintain consistency. You can also create ad blocks for non-widgetized pages of your site. Ad Blocks that are created can be edited or deleted below."); ?>
	<br><br>
	<?php echo $this->translate('<strong class="bold">Note:</strong> These Ad Blocks are only for Community Ads. To display Sponsored Stories on a page, please go to the “Layout” > “Layout Editor” section and place the “Sponsored Stories Widget” at the desired location.'); ?>
  </p>

  <br style="clear:both;" />

	<?php
	if( !empty($this->page_id) && ($this->page_id != 2) ) {
		if( empty($this->check) ) {
			if( $this->page_id == 'none' ) {
				echo '<ul class="form-notices" style="clear:both;margin-bottom:0px;"><li style="margin:0px;"><div style="text-transform:none;">'. $this->translate('The ad block has been created successfully. You now need to copy-paste its code in your desired template file at the appropriate place. To view that code, please click on "code" under "Options" for that Ad Block entry below.'). '</div></li></ul><br/>';
			}else {
				echo '<ul class="form-notices" style="clear:both;margin-bottom:0px;"><li style="margin:0px;"><div style="text-transform:none;">'. $this->translate('The ad block has been created successfully. You may now place this ad block widget on the widgetized page at the desired location from the Layout Editor.'). '</div></li></ul><br/>';
			}
		}else {
				echo '<ul class="form-notices" style="clear:both;margin-bottom:0px;"><li style="margin:0px;"><div style="text-transform:none;">'. $this->translate('The ad block has been created successfully and placed on the desired widgetized page. To adjust the vertical positioning of the ad block on this page, please go to the Layout Editor.'). '</div></li></ul><br/>';
		}
	}
	?>
	
  <?php
	// Show link for "Create Featured Content".
		echo $this->htmlLink(array('route' => 'admin_default', 'module' => 'communityad', 'controller' => 'widgets', 'action' => 'widgetsettings'), $this->translate("Create New Ad Block"), array('class'=>'buttonlink cmad_icon_create'));
	?>
	<?php
	// Show link for "Guidelines to display ads over Non-widgetized pages".
		echo $this->htmlLink(array('route' => 'admin_default', 'module' => 'communityad', 'controller' => 'settings', 'action' => 'guidelines'), $this->translate("Guidelines for placing Ad Blocks on Non-widgetized Pages"), array('class'=>'buttonlink cmad_icon_help'));
	?>
	<br /><br />

<?php
	if( count($this->paginator) ):
?>
<form id='multidelete_form' method="post" action="<?php echo $this->url();?>" onSubmit="return multiDelete();">
  <table class='admin_table'>
    <thead>
      <tr>
        <th class='admin_table_short'>
        	<input onclick='selectAll();' type='checkbox' class='checkbox' />
        </th>
        <th class='admin_table_short' align="center">
					<?php 
						if( empty($this->id_orderby) ) { $orderby = 1; } else { $orderby = 0; }
						echo "<a href=" . $this->url(array('module' => 'communityad', 'controller' => 'widgets', 'action' => 'manage', 'idSorting' => $orderby), 'admin_default', true) . ">" . $this->translate("ID") . '</a>';
					?>
        </th>
         <th align="left">
        	<?php echo $this->translate("Ad Block Title"); ?>
        </th>
        <th align="left">
        	<?php echo $this->translate("Page Type"); ?>
        </th>
        <th align="left">
        	<?php echo $this->translate("Widget Name"); ?>
        </th>
        <th class="admin_table_centered">
        	<?php echo $this->translate("Creation Date"); ?>
        </th>
        <th class="admin_table_centered">
        	<?php echo $this->translate("Limit"); ?>
        </th>
				<th class="admin_table_centered" title="<?php echo $this->translate('Ajax Based Display') ?>">
        	<?php echo $this->translate("Ajax Based"); ?>
        </th>
        <th align="left">
        	<?php echo $this->translate("Options"); ?>
        </th>
      </tr>
    </thead>
    <tbody>
    	<?php foreach ($this->paginator as $item):?>				
        <tr>
          <td><input type='checkbox' name='delete_<?php echo $item->pagesetting_id;?>' value='<?php echo $item->pagesetting_id ?>' class='checkbox' value="<?php echo $item->pagesetting_id ?>" <?php if( $item->ad_widget_id == 50 ){ echo 'DISABLED'; } ?> /></td>
          <td class="admin_table_centered"><?php echo $item->pagesetting_id; ?></td>
					<td title="<?php echo ucfirst($item->ad_block_title); ?>"><?php echo  $this->translate(ucfirst(Engine_Api::_()->communityad()->truncation($item->ad_block_title, 20))); ?></td>
          <?php
						if ( !empty($item->displayname) ) {						
							$displayname = Engine_Api::_()->communityad()->truncation($item->displayname,20);
						} else {
							$displayname = $this->translate('Non-Widgetized Page') ;
						}
					?>
          <td title="<?php echo strip_tags($item->displayname)?>"><?php echo $displayname; ?></td>
					<?php
					if( !empty($item->ad_widget_id) ) {
						$widgetInfo = Engine_Api::_()->getDbtable('pagesettings', 'communityad')->adwidgetInfo($item->ad_widget_id);
					}
					?>
          <td title="<?php echo $widgetInfo['placement']; ?>"><?php echo Engine_Api::_()->communityad()->truncation($widgetInfo['placement'], 25); ?></td>
          <td class="admin_table_centered"><?php echo date('M d, Y', strtotime($item->creation_date)) ?></td>
					<td class="admin_table_centered"><?php echo $item->value; ?></td>

       			<!--AJAX BASED OR NOT--> 
					<?php if(!empty($item->ajax_enabled)):?>
						<td align="center" class="admin_table_centered"> 
							<?php 
								echo $this->htmlLink(array('route' => 'admin_default', 'module' => 'communityad', 'controller' => 'widgets', 'action' => 'ajaxadsenable', 'pagsettingId' => $item->pagesetting_id), $this->htmlImage($this->layout()->staticBaseUrl . 'application/modules/Communityad/externals/images/communityad_approved1.gif', '', array('title'=> $this->translate('Disable Ajax based Display')))) 
							?>
						</td>
					<?php else: ?>
						<td align="center" class="admin_table_centered">
							<?php 
								echo $this->htmlLink(array('route' => 'admin_default', 'module' => 'communityad', 'controller' => 'widgets', 'action' => 'ajaxadsenable', 'pagsettingId' => $item->pagesetting_id), $this->htmlImage($this->layout()->staticBaseUrl . 'application/modules/Communityad/externals/images/communityad_approved0.gif', '', array('title'=> $this->translate('Enable Ajax based Display'))))
							?>
					  </td>
					<?php endif; ?>

          <td>
          <?php
						if ( empty($item->page_id) ) {
							$pageId = 'none';
						} else {
							$pageId = $item->page_id;
						}
						echo $this->htmlLink(array('route' => 'admin_default', 'module' => 'communityad', 'controller' => 'widgets', 'action' => 'widgetsettings', 'page_id' => $pageId, 'widget_id' => $item->ad_widget_id, 'edit' => $item->pagesetting_id), $this->translate("edit")) . ' | ';
						// Condition: for footer widgets we are showing disabled link else we are showing delete link.
						if( $item->ad_widget_id != 50 ) {
							echo $this->htmlLink(array('route' => 'admin_default', 'module' => 'communityad', 'controller' => 'widgets', 'action' => 'delete', 'pagsettingId' => $item->pagesetting_id), $this->translate("delete"), array('class' => 'smoothbox'));
						}else {
							echo $this->htmlLink(array('route' => 'admin_default', 'module' => 'communityad', 'controller' => 'widgets', 'action' => 'footermsg', 'pagsettingId' => $item->pagesetting_id), $this->translate("enable/disable"), array('class' => 'smoothbox'));
						}
						if ( empty($item->displayname) && empty($item->params) ) {
							echo ' | ' . $this->htmlLink(array('route' => 'admin_default', 'module' => 'communityad', 'controller' => 'widgets', 'action' => 'none-widget-code', 'adWidgetId' => $item->ad_widget_id), $this->translate("code"), array('class' => 'smoothbox'));
						}
					?>
          </td>
        </tr>
      <?php endforeach; ?>
    </tbody>
  </table>
  <br />
  <div class='buttons'>
  	<button type='submit'><?php echo $this->translate("Delete Selected") ?></button>
  </div>
</form>
<br />
<div>
	<?php echo $this->paginationControl($this->paginator); ?>
</div>
<?php else: ?>
  <div class="tip">
    <span>
      <?php echo $this->translate("You have not created any ad blocks from here for your site.") ?>
    </span>
  </div>
<?php endif; ?>